package com.brillilab.service.core.kit.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.brillilab.dao.mapper.kit.SampleAttrMapper;
import com.brillilab.domain.po.kit.SampleAttr;
import com.brillilab.service.core.kit.ISampleAttrService;

@Service
@Transactional
public class SampleAttrServiceImpl implements ISampleAttrService {
	@Autowired
	private SampleAttrMapper sampleAttrMapper;

	
	@Override
	public SampleAttr insert(SampleAttr entity) {
		Integer insert = sampleAttrMapper.insert(entity);
		Assert.isTrue(insert == 1, "添加失败");
		return entity;
	}


	@Override
	public boolean deleteById(Long id) {
		Integer b = sampleAttrMapper.deleteById(id);
		return b == 1 ? true : false;
	}

	@Override
	public boolean updateById(SampleAttr entity) {
		entity.setUpdateTime(new Date());
		Integer b = sampleAttrMapper.updateById(entity);
		return b == 1 ? true : false;
	}

	@Override
	public SampleAttr selectById(Long id) {
		return sampleAttrMapper.selectById(id);
	}

	@Override
	public List<SampleAttr> selectList(Long kitId) {
		LambdaQueryWrapper<SampleAttr> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(SampleAttr::getKitId, kitId);
		return sampleAttrMapper.selectList(wrapper);
	}


	@Override
	public List<SampleAttr> insertBatch(List<SampleAttr> attrList) {
		Integer rs = sampleAttrMapper.insertBarth(attrList);
		 Assert.isTrue(rs == attrList.size(),"操作失败！");
		return attrList;
	}


	@Override
	public void deleteByKitId(Long kitId) {
		LambdaQueryWrapper<SampleAttr> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(SampleAttr::getKitId, kitId);
		sampleAttrMapper.delete(wrapper);
	}

}
